package cool.taomu.tookit.demo.test

import cool.taomu.toolkit.Taomu
import cool.taomu.toolkit.demo.stock.entity.StockHistory
import cool.taomu.toolkit.demo.stock.service.DeviationService
import cool.taomu.toolkit.stock.dao.jooq.tables.TaomuStockHistory
import java.time.LocalDateTime
import java.time.temporal.ChronoUnit
import javax.inject.Inject
import org.jooq.DSLContext
import org.junit.jupiter.api.Test

class StockPojoTest {

	long xDays = 1
	
	@Inject
	DSLContext dsl
	
	String ncode = "sh.600000"
	
	@Test
	def void a() {
		var inject = Taomu.run()
		var t = inject.getInstance(StockPojoTest)
		val endDate = LocalDateTime.now().toLocalDate().atStartOfDay();
		val startDate = endDate.minus(xDays, ChronoUnit.DAYS).toLocalDate().atStartOfDay();
		var stockHistorylist = t.dsl.selectFrom(TaomuStockHistory.TAOMU_STOCK_HISTORY).where(
			TaomuStockHistory.TAOMU_STOCK_HISTORY.CODE.eq(ncode)).and(
			TaomuStockHistory.TAOMU_STOCK_HISTORY.DATE.greaterOrEqual(startDate)
		).and(TaomuStockHistory.TAOMU_STOCK_HISTORY.DATE.lessOrEqual(endDate)).orderBy(
			TaomuStockHistory.TAOMU_STOCK_HISTORY.DATE.asc()).fetchInto(StockHistory)
		
		println(stockHistorylist)
	}
	
	@Test
	def void bl(){
		var inject = Taomu.run()
		var ctrl = inject.getInstance(DeviationService)
		ctrl.deviationEvel(5,ncode)
	}
}
